﻿using System;
using UnityEngine;

namespace Script.Structs.Pawn
{
    /// <summary>
    /// 棋子模板填表属性
    /// </summary>
    public struct PawnPropertyModel
    {
        ///<smmary>
        ///棋子id
        ///</summary>
        public string Id;
        ///<smmary>
        ///棋子名称
        ///</summary>
        public string Name;
        ///<smmary>
        ///棋子外观资产地址
        ///</summary>
        public string AssetsPath;
        ///<summary>
        ///棋子属性
        ///</summary>
        public PawnProperty PawnProperty;

        public PawnPropertyModel(string id, string name, string assetsPath, PawnProperty pawnProperty)
        {
            Id = id;
            Name = name;
            AssetsPath = assetsPath;
            PawnProperty = pawnProperty;
        }
    }
    
    //棋子属性
    public struct PawnProperty
    {
        ///<summary>
        ///最大生命
        ///</summary>
        public int Hp;

        ///<summary>
        ///攻击力
        ///</summary>
        public int Attack;

        ///<summary>
        ///行动力
        ///</summary>
        public int Action;

        ///<summary>
        ///角色移动类型
        ///</summary>
        public MoveType MoveType;

        public PawnProperty(
           int hp, int attack , int action,MoveType moveType = MoveType.Walk)
        {
            this.Hp = hp;
            this.Attack = attack;
            this.Action = action;
            this.MoveType = moveType;
        }

        public static PawnProperty zero = new PawnProperty(0,0,0);

        ///<summary>
        ///将所有值清0
        ///<param name="moveType">移动类型设置为</param>
        ///</summary>
        public void Zero(MoveType moveType = MoveType.Walk)
        {
            this.Hp = 0;
            this.Attack = 0;
            this.Action = 0;
            this.MoveType = moveType;
        }
    }

    ///<summary>
    ///棋子的资源类属性，比如hp都属于这个
    ///</summary>
    public class PawnResource
    {
        ///<summary>
        ///当前生命
        ///</summary>
        public int Hp;

        public PawnResource(int hp)
        {
            this.Hp = hp;
        }

        ///<summary>
        ///是否足够
        ///</summary>
        public bool Enough(PawnResource requirement)
        {
            return (
                this.Hp >= requirement.Hp
            );
        }

        public static PawnResource operator +(PawnResource a, PawnResource b)
        {
            return new PawnResource(
                a.Hp + b.Hp
            );
        }
        public static PawnResource operator *(PawnResource a, float b)
        {
            return new PawnResource(
                Mathf.FloorToInt(a.Hp * b)
            );
        }
        public static PawnResource operator *(float a, PawnResource b)
        {
            return new PawnResource(
                Mathf.FloorToInt(b.Hp * a)
            );
        }
        public static PawnResource operator -(PawnResource a, PawnResource b)
        {
            return a + b * (-1);
        }

        public static PawnResource Null = new PawnResource(0);
    }

    public struct PawnGenInfo
    {
        public string PrefabPath;
        public int Comp;
        public Vector2Int Pos;

        public int Hp;
        public int Attack;
        public int Action;

        public PawnGenInfo(string prefabPath,int comp,Vector2Int pos,int hp,int attack,int action)
        {
            PrefabPath = prefabPath;
            Comp = comp;
            Pos = pos;
            Hp = hp;
            Attack = attack;
            Action = action;
        }
    }
}